package com.one.tank;

import java.awt.*;

//砖块和铁块的父类
public class Block {
    //块类别常量
    public static final int BLOCK_BRICK = 1;
    public static final int BLOCK_IRON = 2;
    //块尺寸常量-->默认4个块=1个坦克的大小
    public final static int BLOCK_WIDTH = Tank.TANK_WIDTH / 2;
    public final static int BLOCK_HEIGHT = Tank.TANK_HEIGHT / 2;
    //块的坐标
    private int x;
    private int y;
    //块的类别
    private int type = BLOCK_BRICK;

    /**
     * 构造函数
     *
     * @param type 块类别
     * @param x    块左上角X坐标
     * @param y    块左上角Y坐标
     */
    public Block(int type, int x, int y) {
        this.type = type;
        this.x = x;
        this.y = y;
    }

    //画块
    public void drawBlock(Graphics g) {
        //砖块-->可以打烂
        if (this.type == BLOCK_BRICK) {
            //砖块的主体部分
            g.setColor(new Color(210, 105, 30));
            g.fillRect(this.x, this.y, BLOCK_WIDTH, BLOCK_HEIGHT);
            //砖块的线条
            g.setColor(new Color(244, 164, 96));
            //绘制上线段，从(x, y)到(x+BLOCK_WIDTH-1, y)
            g.drawLine(this.x, this.y, this.x + BLOCK_WIDTH - 1, this.y);
            //绘制左线段，从(x, y+BLOCK_HEIGHT/2)到(x+BLOCK_WIDTH-1, y+BLOCK_HEIGHT/2)
            g.drawLine(this.x, this.y + BLOCK_HEIGHT / 2, this.x + BLOCK_WIDTH - 1, this.y + BLOCK_HEIGHT / 2);
            //绘制右线段，从(x, y)到(x+BLOCK_WIDTH-1, y+BLOCK_HEIGHT/2)
            g.drawLine(this.x, this.y, this.x, this.y + BLOCK_HEIGHT / 2);
            //绘制下线段，从(x+BLOCK_WIDTH/2, y+BLOCK_HEIGHT/2)到(x+BLOCK_WIDTH/2, y+BLOCK_HEIGHT-1)
            g.drawLine(this.x + BLOCK_WIDTH / 2, this.y + BLOCK_HEIGHT / 2, this.x + BLOCK_WIDTH / 2, this.y + BLOCK_HEIGHT - 1);
        }
        //铁块-->打不烂
        else if (this.type == BLOCK_IRON) {
            //铁块的主体部分
            g.setColor(new Color(190, 190, 190));
            g.fillRect(this.x, this.y, BLOCK_WIDTH, BLOCK_HEIGHT);
            //铁块的线条
            g.setColor(Color.WHITE);
            //更加美观
            g.fillRect(this.x + 3, this.y + 3, BLOCK_WIDTH - 6, BLOCK_HEIGHT - 6);
            //绘制具有3D效果的矩形填充效果
            g.draw3DRect(this.x + 3, this.y + 3, BLOCK_WIDTH - 6, BLOCK_HEIGHT - 6, true);
            //绘制线条
            g.drawLine(this.x + 1, this.y + 1, this.x + 3, this.y + 3);
            g.drawLine(this.x + BLOCK_WIDTH - 1, this.y + 1, this.x + BLOCK_WIDTH - 3, this.y + 3);
            g.drawLine(this.x + 1, this.y + BLOCK_HEIGHT - 1, this.x + 3, this.y + BLOCK_HEIGHT - 3);
            g.drawLine(this.x + BLOCK_WIDTH - 1, this.y + BLOCK_HEIGHT - 1, this.x + BLOCK_WIDTH - 3, this.y + BLOCK_HEIGHT - 3);
        }

    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }
}
